// @APIVersion 1.0.0
// @Title beego Test API
// @Description beego has a very cool tools to autogenerate documents for your API
// @Contact astaxie@gmail.com
// @TermsOfServiceUrl http://beego.me/
// @License Apache 2.0
// @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
package routers

import (
	"backend/controllers"
	"backend/middlewave"
	beego "github.com/beego/beego/v2/server/web"
)

func init() {

	// 跨域中间件
	beego.InsertFilter("*",beego.BeforeRouter,middlewave.CorsHandler)

	// 鉴权中间件
	beego.InsertFilter("/v1/file/*", beego.BeforeRouter, middlewave.CheckToken)
	beego.InsertFilter("/v1/user/*", beego.BeforeRouter, middlewave.CheckAccess)
	beego.ErrorController(&controllers.ErrorController{})

	ns := beego.NewNamespace("/v1",
		beego.NSNamespace("/user",
			beego.NSInclude(
				&controllers.UserController{},
			),
		),
		beego.NSNamespace("/file",
			beego.NSInclude(
				&controllers.FileController{},
			),
		),
	)
	beego.AddNamespace(ns)
}
